ifeq (,$(wildcard ../config.mak))
$(error "../config.mak is not present, run configure !")
endif
include ../config.mak

PROG = urobot

EXTRADIST = urobot.1 \
	cms.h \
	mcs.h \
	sms.h \
	cam.h \
	http.h \
	presentation.h \
	mime.h \
	services.h \
	buffer.h \
	cfgparser.h \
	trace.h \
	osdep.h \
	urobot.h \
	gettext.h \
	utils.h \


SRCS = \
        cms.c \
        mcs.c \
        sms.c \
        cam.c \
        http.c \
        presentation.c \
        mime.c \
        services.c \
        buffer.c \
        cfgparser.c \
        trace.c \
        osdep.c \
        urobot.c

OBJS = $(SRCS:.c=.o)

CFLAGS += -O2 -Os

.SUFFIXES: .c .o

#SUBDIRS = hybus
SUBDIRS = $(TARGET)

all: depend subdirs $(PROG)

.c.o:
	$(CC) -c $(CFLAGS) $(OPTFLAGS) -o $@ $<

subdirs:
	for subdir in $(SUBDIRS); do \
	  $(MAKE) -C $$subdir; \
        done

TARGETLIB = target.a

target.a: $(TARGET)/target.a
	mv $^ .

$(PROG): $(OBJS) $(TARGETLIB)
	@echo $(CC) $(OBJS) $(TARGETLIB) $(LDFLAGS) $(EXTRALIBS) -o $@
	$(CXX) $(OBJS) $(LDFLAGS) $(TARGETLIB) $(EXTRALIBS) -o $@

clean:
	for subdir in $(SUBDIRS); do \
	  $(MAKE) -C $$subdir $@; \
        done
	-$(RM) -f *.o *.a $(PROG)
	-$(RM) -f .depend

distclean: clean
	for subdir in $(SUBDIRS); do \
	  $(MAKE) -C $$subdir $@; \
        done

install: $(PROG)
	$(INSTALL) -d $(bindir)
	$(INSTALL) $(PROG) $(bindir)
	$(STRIP) $(INSTALLSTRIP) $(bindir)/$(PROG)

depend:
	$(CC) -I.. -MM $(CFLAGS) $(SRCS) 1>.depend

.PHONY: clean distclean install depend

dist-all:
	cp $(EXTRADIST) $(SRCS) Makefile $(DIST)

.PHONY: dist-all

#
# include dependency files if they exist
#
ifneq ($(wildcard .depend),)
include .depend
endif
